package com.amit.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class EnquiryIdAction extends Action {
	
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		//1.collect the data
		EnquiryIdForm ef=(EnquiryIdForm) form;
		
		String eid=ef.getEnquiryId();
		
		//2.contact the model
		
		String result=" ";
		
		if(eid.equals("E-1001"))
		{
			result="success";
			
			EnquiryTO  eto=new EnquiryTO();
			eto.setEid(eid);
			eto.setFullname("amit yadav");
			eto.setEmail("amit@gmail.com");
			eto.setPhone("7259745608");
			eto.setTimings("6:30-8:30");
			request.setAttribute("ETO", eto);
			
		}
		else
		{
		result="failed";
		ActionErrors errors=new ActionErrors();
		errors.add("enquiryId", new ActionError("error.enquiry.Id.notfound"));
		this.saveErrors(request, errors);
		
		}
		
		ActionForward forward=mapping.findForward(result);
		
		return forward;
	}

}
